package it.hive.controller.renderer;

import it.hive.mediaplayer.beans.interfaces.RemoteMedia;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.image.ImageView;
import javafx.util.Callback;

public class CustomListCell<T extends RemoteMedia> extends ListCell<T> {

	@Override
	public void updateItem(T arg0, boolean arg1) {
		super.updateItem(arg0, arg1);
		if (arg0 != null) {
			setText(arg0.toString());
			if (((it.hive.mediaplayer.beans.interfaces.RemoteMedia) arg0).getImmagine() != null) {
				ImageView image = new ImageView(((it.hive.mediaplayer.beans.interfaces.RemoteMedia) arg0).getImmagine());
				image.setPreserveRatio(true);
				image.fitWidthProperty().bind(new SimpleDoubleProperty(150));
				setGraphic(image);
			}
		}
	}

	public Callback<ListView<T>, ListCell<T>> getCellFactory() {
		return new Callback<ListView<T>, ListCell<T>>() {
			@Override
			public ListCell<T> call(ListView<T> list) {
				return new CustomListCell<T>();
			}
		};
	}

}
